const app = getApp()
Page({
  data: {
    disabled:false,
    userId: "",
    userName: "",
    phone: "",
    userCode: "",
    orgId: "",
    employeeCode: "",
    orgCode: "",
    orgName: "",
    noinput:false,
    pwdinput:false,
  },
  noinput:function(e){
    this.setData({no:e.detail.value});
    this.setData({noinput:true});
    if(this.data.noinput==true && this.data.pwdinput==true){
      this.setData({ disabled: false });
    }
  },
  orginput:function (e) {
    this.setData({ pwd: e.detail.value });
    this.setData({ pwdinput: true });
    if (this.data.noinput == true && this.data.pwdinput == true) {
      this.setData({ disabled: false });
    }
  },
  
  formSubmit: function (e) {
    wx.showLoading({
      title: '登录中...',
    })
    console.log(e);
    this.setData({ disabled: true});
    wx.request({
      url: 'http://172.18.8.103:9010/staff/'+ e.detail.value.employeeCode+"/"+ e.detail.value.orgCode, 
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res);
        if (res.statusCode == 200) {
          if (res.data.success == true) {
            console.info(res.data.data)
            wx.setStorage({
              data: res.data.data,
              key: 'userInfo',
            })
            wx.showToast({
              title: res.data.message,
              icon: 'success',
              duration: 2000
            })
            wx.navigateTo({
              url: './index'
            });
          } else {
            wx.showToast({
              title: res.data.message,
              icon: 'none',
              duration: 2000
            })
          }
        }else{
          wx.showToast({
            title: '服务器出现错误',
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  set() {
    try {
        wx.setStorageSync('employeeCode', 'orgCode')
    } catch (e) { }
},
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(this.data.no=='' || this.data.pwd==''){
      this.setData({ disabled: true });
    }else{
      this.setData({ disabled: false });
    }
  },
 
 
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  }
})
